﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BLL.BussinessInterface;
using DAL;
using Model;

namespace BLL.BussinessClass
{
    public class OrderBiz : IOrderBiz
    {
        #region IOrder成员
        public List<ORDER> GetOrderList()
        {
            OrderRepository repo = OrderRepository.Instrance;
            return repo.LoadOrderXML();
        }


        public bool OrderItem(ITEM item)
        {
            if (null == item)
            {
                return false;
            }
            OrderRepository repo = OrderRepository.Instrance;
            string orderID = DateTime.Now.ToString("yyyyMMdd");
            return repo.OrderItem(orderID, item);
        }


        public List<ITEM> LoadTodayOrderItemList()
        {
            OrderRepository repo = OrderRepository.Instrance;
            string orderID = DateTime.Now.ToString("yyyyMMdd");
            return repo.LoadOrderItemList(orderID);
        }

        public List<ITEM> LoadOrderItemList(DateTime orderDate)
        {
            OrderRepository repo = OrderRepository.Instrance;
            string orderID = orderDate.ToString("yyyyMMdd");
            return repo.LoadOrderItemList(orderID);
        }

        public List<ITEM> LoadUserItemHistoryList(string userName, bool loadEarlierHistory = false)
        {
            OrderRepository repo = OrderRepository.Instrance;
            List<ITEM> itemList = new List<ITEM>();
            itemList = repo.LoadItemList().Where(c => c.NAME == userName).ToList();

            if (loadEarlierHistory)
            {
                //To Do
            }
            return itemList;
        }

        public bool DeleteItem(string orderID, string itemID)
        {
            OrderRepository repo = OrderRepository.Instrance;
            if (string.IsNullOrEmpty(orderID) || string.IsNullOrEmpty(itemID))
            {
                return false;
            }
            return repo.DeleteItem(orderID, itemID);
        }

        #endregion
    }
}
